function [FCMAP5] = make_cmap5(PCNAME,PNCOL)
% make_cmap5
%
%   *******************************************************************   %
%   *** make colorbar color scale *************************************   %
%   *******************************************************************   %
%
%   make_cmap5( ... )
%   creates an evenly-spaced color scale of a given number of colors
%
%   PCNAME [STRING]
%   --> name of colorbar colorscale
%   PNCOL [integer]
%   --> the number of colors
%
%   The color scale options are:
%
%   (1) One of the original MATLAB colorscales:
%       'jet','hsv','hot','cool','spring','summer','autumn','winter',
%       'gray','bone','copper','pink'
%   (2) The new MATLAB (2014 release) default (the 'jet' replacement):
%       'parula'
%   (3) An alternative rainbow replacement:
%       'CubicYF'
%       http://mycarta.wordpress.com/2013/02/21/perceptual-rainbow-palette-
%       the-method/
%       http://www.mathworks.com/matlabcentral/fileexchange/28982-perceptua
%       lly-improved-colormaps/content/pmkmp/pmkmp.m
%       (note that this color scheme is only approximated here)
%   (4) One of the divergent cbrewer schemes
%       'BrBG', 'PiYG', 'PRGn', 'PuOr', 'RdBu', 'RdGy', 'RdYlBu', 'RdYlGn'
%       http://colorbrewer2.org/
%       http://uk.mathworks.com/matlabcentral/fileexchange/34087-cbrewer---
%       colorbrewer-schemes-for-matlab
%       (note that these color schemes are only approximated here)
%   (5) One of the built-in/internal color schemes:
%       'anom' -- is the existing anomoly color scehem (blue-white-red)
%       '_parula' -- is an approximation of the parula m-function
%
%   The default is 'parula', and if parula.m is not available,
%   the approximateion '_parula' is used instead.
%
%   Original author:
%   Andy Ridgwell <andy@seao2.org>
%
%   License:
%   CC BY-NC-SA 3.0 (http://creativecommons.org/licenses/by-nc-sa/3.0/)
%
%   *******************************************************************   %

% *********************************************************************** %
% ***** HISTORY ********************************************************* %
% *********************************************************************** %
%
%   14/12/03: CREATED
%   15/01/01: adjustment to default colotmap
%   15/01/09: re-wrote the 're-gridding' of the color map
%   15/01/11: added 'LinearL' color scheme
%
% *********************************************************************** %

% *********************************************************************** %
% *** INITIALIZE PARAMETERS & VARIABLES ********************************* %
% *********************************************************************** %
%
% process dummy parameters
str_name = PCNAME;
col_n = PNCOL;
%
col_m = 10000;
loc_str_cmap = [];
%
% *********************************************************************** %

% *********************************************************************** %
% *** CREATE COLOR SCALE ************************************************ %
% *********************************************************************** %
%
% *** SET UP TIE-POINTS ************************************************* %
%
% create tie point indices
% NOTE: this is for *5*, evenly-spaced tie-points (with #3 centered)
c1 = 1;
c2 = col_m/4;
c3 = col_m/2;
c4 = 3*col_m/4;
c5 = col_m;
%
% *** SET TIE-POINT COLORS ********************************************** %
%
switch str_name
    case {'anom'}
        i1 = [0 0 255];
        i2 = [127 255 255];
        i3 = [255 255 255];
        i4 = [255 255 127];
        i5 = [255 0 0];
    case {'_parula'}
        i1 = [0.208100000000000   0.166300000000000   0.529200000000000];
        i2 = [0.079475000000000   0.515900000000000   0.832825000000000];
        i3 = [0.198550000000000   0.721400000000000   0.630950000000000];
        i4 = [0.826575000000000   0.732025000000000   0.346350000000000];
        i5 = [0.976300000000000   0.983100000000000   0.053800000000000];
    case {'RdYlGn'}
        i1 = [                0   0.407843137254902   0.215686274509804];
        i2 = [0.525490196078432   0.796078431372549   0.401960784313726];
        i3 = [1.000000000000000   1.000000000000000   0.749019607843137];
        i4 = [0.974509803921569   0.554901960784314   0.321568627450980];
        i5 = [0.647058823529412                   0   0.149019607843137];
    case {'RdYlBu'}
        i1 = [0.192156862745098   0.211764705882353   0.584313725490196];
        i2 = [0.562745098039216   0.764705882352942   0.866666666666666];
        i3 = [1.000000000000000   1.000000000000000   0.749019607843137];
        i4 = [0.974509803921569   0.554901960784314   0.321568627450980];
        i5 = [0.647058823529412                   0   0.149019607843137];
    case {'RdGy'}
        i1 = [0.101960784313725   0.101960784313725   0.101960784313725];
        i2 = [0.629411764705882   0.629411764705882   0.629411764705882];
        i3 = [                1                   1                   1];
        i4 = [0.898039215686275   0.511764705882353   0.405882352941176];
        i5 = [0.403921568627451                   0   0.121568627450980];
    case {'RdBu'}
        i1 = [0.019607843137255   0.188235294117647   0.380392156862745];
        i2 = [0.417647058823529   0.674509803921569   0.817647058823529];
        i3 = [0.968627450980392   0.968627450980392   0.968627450980392];
        i4 = [0.898039215686275   0.511764705882353   0.405882352941176];
        i5 = [0.403921568627451                   0   0.121568627450980];
    case {'PuOr'}
        i1 = [0.176470588235294                   0   0.294117647058824];
        i2 = [0.600000000000000   0.560784313725490   0.749019607843137];
        i3 = [0.968627450980392   0.968627450980392   0.968627450980392];
        i4 = [0.935294117647059   0.615686274509804   0.233333333333333];
        i5 = [0.498039215686275   0.231372549019608   0.031372549019608];
    case {'PRGn'}
        i1 = [                0   0.266666666666667   0.105882352941176];
        i2 = [0.501960784313725   0.770588235294118   0.503921568627451];
        i3 = [0.968627450980392   0.968627450980392   0.968627450980392];
        i4 = [0.680392156862745   0.543137254901961   0.741176470588235];
        i5 = [0.250980392156863                   0   0.294117647058824];
    case {'PiYG'}
        i1 = [0.152941176470588   0.392156862745098   0.098039215686275];
        i2 = [0.609803921568628   0.809803921568627   0.390196078431373];
        i3 = [0.968627450980392   0.968627450980392   0.968627450980392];
        i4 = [0.907843137254902   0.590196078431373   0.768627450980392];
        i5 = [0.556862745098039   0.003921568627451   0.321568627450980];
    case {'BrBG'}
        i1 = [                0   0.235294117647059   0.188235294117647];
        i2 = [0.354901960784314   0.698039215686274   0.658823529411765];
        i3 = [0.960784313725490   0.960784313725490   0.960784313725490];
        i4 = [0.811764705882353   0.633333333333333   0.333333333333333];
        i5 = [0.329411764705882   0.188235294117647   0.019607843137255];
    case {'LinearL'}
        i1 = [0.014300000000000   0.014300000000000   0.014300000000000];
        i2 = [0.123672554542508   0.199537383180633   0.492799047095616];
        i3 = [0                   0.516521346240629   0.296861083234749];
        i4 = [0.457876480046909   0.763504593047024                   0];
        i5 = [0.969200000000000   0.927300000000000   0.896100000000000];
    case {'CubicYF'}
        i1 = [0.515100000000000   0.048200000000000   0.669700000000000];
        i2 = [0.399949827667760   0.456368933183748   0.983194421965318];
        i3 = [0.230121107544141   0.737705174960222   0.676157059608085];
        i4 = [0.377847964529031   0.896838650322670   0.292763123337766];
        i5 = [0.800000000000000   0.925500000000000   0.352900000000000];
    case {'jet','hsv','hot','cool','spring','summer','autumn','winter','gray','bone','copper','pink'}
        if (exist(str_name) == 0),
            disp(['ERROR: colormap ', str_name, ' does not exist.']);
            return;
        else
            loc_str_cmap = str_name;
        end
    otherwise
        if (exist('parula') == 2 || exist('parula') == 5),
            loc_str_cmap = 'parula';
        else
            i1 = [0.208100000000000   0.166300000000000   0.529200000000000];
            i2 = [0.079475000000000   0.515900000000000   0.832825000000000];
            i3 = [0.198550000000000   0.721400000000000   0.630950000000000];
            i4 = [0.826575000000000   0.732025000000000   0.346350000000000];
            i5 = [0.976300000000000   0.983100000000000   0.053800000000000];
        end
        disp(['WARNING: colormap ', str_name, ' cannot be found => using default.']);
end
%
% *** CREATE COLOR SCALE ************************************************ %
%
if ~isempty(loc_str_cmap),
    cmap = colormap(eval([loc_str_cmap '(' num2str(col_n) ')']));
else
    % create high resolution color scale
    c = c1;
    loc_cmap(c,:) = abs(i1);
    for c = c1+1:c2,
        loc_cmap(c,:) = i1 + ((c-c1)/(c2-c1))*(i2 - i1);
    end
    for c = c2+1:c3,
        loc_cmap(c,:) = i2 + ((c-c2)/(c3-c2))*(i3 - i2);
    end
    for c = c3+1:c4,
        loc_cmap(c,:) = i3 + ((c-c3)/(c4-c3))*(i4 - i3);
    end
    for c = c4+1:c5,
        loc_cmap(c,:) = i4 + ((c-c4)/(c5-c4))*(i5 - i4);
    end
    % interpolate color scale to desired number of colors
    loc_c = int16([1:((col_m-1)/(col_n-1)):col_m]);
    cmap = loc_cmap(loc_c,:);
end
%
% *********************************************************************** %

% *********************************************************************** %
% *** END *************************************************************** %
% *********************************************************************** %
%
% export data
FCMAP5 = cmap;
%
% *********************************************************************** %
